#!/usr/bin/env  node

const mysql=require('mysql2/promise'),
      log=console.log;

let con =mysql.createPool({
  host:'127.0.0.1',
    user:'root',
    password:'ddd',
    database:'test1'

});







 async function getAreas(){
  const sql='select * from areas';
  let [result]= await  con.execute(sql);

  log(result);
  //exectue sql
}


(async function(){
      await getAreas();

})();


async function addAreas(areaName){
      const sql = `insert into areas (area_name) values('${areaName}')`;
          let [rows] =  await con.execute(sql);
              // console.log(result);
              //     return rews;
              //
              //
            return rows;
}


(async function(){
        await addAreas('匈牙利');


})();


async function updateAreas(oldName,newName){
      const sql = `update  areas set  area_name='${newName}'  where area_name='${oldName}'`;
          let [rows] =  await con.execute(sql);
          return rows;
}

(async function(){
        await updateAreas('港澳台','中国港澳台');
        log(getAreas());
})();

async function deleteAreas(areaName){
      const sql = `delete from areas where area_name = '${areaName}'`;
          let [rows] =  await con.execute(sql);
              return rows;             
}

(async function(){
        await deleteAreas('日韩');
        log(getAreas());


})();
